package com.xinqi.modules.chat.chat.message.manager.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.core.utils.MessageUtils;
import com.xinqi.common.mybatis.data.service.impl.BaseServiceImpl;
import com.xinqi.modules.chat.chat.message.domain.ChatEmojiMessageEntity;
import com.xinqi.modules.chat.chat.message.manager.ChatEmojiMessageManager;
import com.xinqi.modules.chat.chat.message.mapper.ChatEmojiMessageMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * 聊天消息自定义表情表管理层实现
 *
 * @author: yyzhen
 * @date: 2023/07/11
 */
@Service
@RequiredArgsConstructor
public class ChatEmojiMessageManagerImpl extends BaseServiceImpl<ChatEmojiMessageMapper, ChatEmojiMessageEntity> implements ChatEmojiMessageManager {

    /**
     * 查询用户的自定义表情
     *
     * @param userId
     * @return
     */
    @Override
    public List<ChatEmojiMessageEntity> listByUserId(Long userId) {
        CommonErrors.BAD_REQUEST.check(Objects.nonNull(userId), MessageUtils.message("chat.message.emoji.userId.not.blank"));
        LambdaQueryWrapper<ChatEmojiMessageEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ChatEmojiMessageEntity::getUserId, userId)
            .orderByDesc(ChatEmojiMessageEntity::getUpdateTime);
        return this.baseMapper.selectList(queryWrapper);
    }

}
